package cn.qy.kotlin.base

import kotlin.test.Test

class Ch02VariablesTest {
    // 常量和变量
    @Test
    fun testVar() {
        // kotlin 可自动推断变量类型
        val x = 20
        // 声明并指定数据类型
        var scoreForStudent: Float = 0.0f
    }

    // 类型转换
    @Test
    fun `Explicit number conversions`() {
        val a: Int = 1
        val b: Long = a.toLong()
    }

    // 位运算
    @Test
    fun `bit`() {
        println(16 shr 3)
        println(16 ushr 3)
    }

    // 字符串
    @Test
    fun `testStr`() {
        val str = "abcd"
        for (c in str) {
            println(c)
        }

        println("abc" + 1)

val text = """
  for (c in "foo")
    print(c)
"""
        println(text)

        val text2 = """
    |Tell me and I forget.
    |Teach me and I remember.
    |Involve me and I learn.
    |(Benjamin Franklin)
    """.trimMargin()
        println(text2)

        val price = """${'$'}"""
        println(price)
    }

    // 无符号整数类型
    @Test
    fun `无符号整数类型`() {
        val b: UByte = 1u  // UByte, expected type provided
        val s: UShort = 1u // UShort, expected type provided
        val l: ULong = 1u  // ULong, expected type provided

        val a1 = 42u // UInt: no expected type provided, constant fits in UInt
        val a2 = 0xFFFF_FFFF_FFFFu // ULong: no expected type provided, constant doesn't fit in UInt
    }
}
